package com.rtech.operator;

import java.util.Scanner;


public class NumberInBinary {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("Enter Number >>>");
		int x = sc.nextInt();
		
		System.out.println("Binary representation >>>");
		
		System.out.println(Integer.toBinaryString(x));
		
		
		int i = -1;
		System.out.println(Integer.toBinaryString(i));
		// 11111111111111111111111111111111
		
		NumberInBinary num = new NumberInBinary();
		int k = num.extractBits(2, 32);
		System.out.println("k = "+k);
		System.out.println(Integer.toBinaryString(i));
		// 11111111111111111111111111111111
		
		i = i << -5 >>> -5;
		System.out.println(Integer.toBinaryString(i));
	}

	 
	 
	  public int extractBits(int x, int numBits) {
	    if (numBits < 1) {
	        return 0;
	    }
	    if (numBits > 32) {
	        return x;
	    }
	    int mask = (1 << numBits) - 1;
	    return x & mask;
	} 
	
}
